package it.win4buy.mock
{
    import flash.events.IEventDispatcher;
    import flash.utils.setTimeout;

    import it.win4buy.entities.UserDataVO;
    import it.win4buy.events.GetPlaceHolderEvent;
    import it.win4buy.events.UtilityEvent;

    import mx.collections.ArrayCollection;
    import mx.rpc.events.ResultEvent;
    import mx.rpc.remoting.RemoteObject;

    /**
     *
     *	autore:
     *  pierangelo.mancusi@gmail.com
     *
     */

    public class RemoteObjectMock extends RemoteObject
    {



        //-------------------------------------------
        //
        // Injected properties
        //
        //-------------------------------------------

        [Dispatcher]
        public var dispatcher:IEventDispatcher
        //-------------------------------------------
        //
        // Private Properties
        //
        //-------------------------------------------

        private var data:ArrayCollection;

        private var user:UserDataVO;

        //-------------------------------------------
        //
        // Getters / Setters
        //
        //-------------------------------------------


        //-------------------------------------------
        //
        // Constructor
        //
        //-------------------------------------------

        public function RemoteObjectMock()
        {
            data=new ArrayCollection();
            user=new UserDataVO();
            init();
        }

        //-------------------------------------------
        //
        // Mediator Handlers
        //
        //-------------------------------------------

        //-------------------------------------------
        //
        // Public Methods
        //
        //-------------------------------------------

        /**
         *Used by GetPlaceHolderService
         *
         */
        public function getPlaceHolder():void
        {
            setTimeout(servicePlaceHolderResult, 500);

        }

        /**
         *  Used by GetUserDataService
         *
         */
        public function getUserData(userId:String):void
        {

            setTimeout(serviceUserDataResult, 500);

        }


        public function registerPlaceHolder(userId:String, placeHolderId:String):void
        {
            setTimeout(serviceRegisterPlaceHolderResult, 500);


        }

        //-------------------------------------------
        //
        // Private Methods
        //
        //-------------------------------------------
        private function init():void
        {
            //sets data returned to placeHolder
            for (var i:int=0; i <= 100; i++)
            {
                var o:Object=new Object();
                o.name="nomeTavolo_" + i;
                o.categoria="Sit&Go";
                o.domande=i + " / " + i + "min";
                o.level=i + "/ " + i + "€";
                o.sign=i + " / 10";
                o.number=i;
                o.icons="";
                data.addItem(o);
            }


            //sets user data returned
            user.userName="PETRUS";
            user.credits="199";
            user.freeCredits="1000";
            user.userId="43";

        }


        private function servicePlaceHolderResult():void
        {

            dispatchEvent(new ResultEvent(ResultEvent.RESULT, true, false, data));
        }


        private function serviceUserDataResult():void
        {
            dispatchEvent(new ResultEvent(ResultEvent.RESULT, true, false, user));
        }


        private function serviceRegisterPlaceHolderResult():void
        {
            var data:ArrayCollection=new ArrayCollection();


            for (var i:int=0; i <= 100; i++)
            {
                var o:Object=new Object();
                o.name="cmabioTavolo" + i;
                o.categoria="Sit&Go";
                o.domande=i + " / " + i + "min";
                o.level=i + "/ " + i + "€";
                o.sign=i + " / 10";
                o.number=i;
                o.icons="";
                data.addItem(o);
            }
            dispatchEvent(new ResultEvent(ResultEvent.RESULT, true, false, data));
        }





    }
}